import socket
import random

obj = socket.socket()

HID = "F0012"




#测试使用的代码，自动生成不同的HID


HID = "HID" + str(random.randint(100,999))
print(HID)



print("device mock");
obj.connect(("120.78.131.5",8000))
#obj.connect(("192.168.159.1",8888));




#login

loginstr ='''{
  "cmd": "login",
  "tx_hid": "%s",
  "index": 1
}
'''%HID

obj.send(loginstr.encode("ascii"))



#TODO 需要判断登录是否成功了

while True:
    
    buf = obj.recv(1024)
    if(buf):
        print(buf)
    else:
        print("server close")
        break
    


